package com.example.crm.controller;

import com.example.crm.entity.Contact;
import com.example.crm.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 联系人页面控制器
 */
@Controller
@RequestMapping("/contact")
public class ContactViewController {

    @Autowired
    private ContactService contactService;

    /**
     * 联系人列表页面
     */
    @GetMapping("/list")
    public String list() {
        return "contact/list";
    }

    /**
     * 联系人新增页面
     */
    @GetMapping("/add")
    public String add() {
        return "contact/add";
    }

    /**
     * 联系人编辑页面
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable Long id, Model model) {
        model.addAttribute("contact", contactService.getContactDetail(id));
        return "contact/edit";
    }

    /**
     * 联系人详情页面
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable Long id, Model model) {
        model.addAttribute("contact", contactService.getContactDetail(id));
        return "contact/detail";
    }
} 